from django.template import Template, Context

from game.actions.models import action, TARGET_TYPES
#from game.combat.models import combatant

class actionRequest():
    
    def __init__(self, act, caller, target):
        self.action = action.objects.get(act)
        self.caller = combat.objects.get(caller)
        self.target = combat.objecs.get(target)
    
    def validateRequest(self):
        pass
    
    def getResult(self):
            caller.expendMP(self.action.mpNeeded)
            return self.action.getResults(self.caller, self.target)
        
    def getSuccess(self):
            return self.action.getSuccess(self.caller, self.target)
        
    def onSuccess(self):   
            return self.action.onSuccess(self.caller, self.target)
    
    def onFailure(self):
            return self.action.onFailure(self.caller, self.target)
        
    def getAttemptMessage(self):
            c = Context({"caller":self.caller.individual, "target":self.target.individual})
            return Template(self.action.getAttemptMessage(self.caller, self.target)).render(c)
    
    
class actionResult():
    
    def __init__(self):
        self.success = False
        self.text = None
        self.event = None
        
class InvalidTargetException(Exception):
    """An attempt was made to execute an action against an invalid target"""